<?php
namespace ac\modules\company\controllers;

use Yii;
use ac\controllers\AuthController;
use app\models\CompanyAccountRecord;
use app\models\CompanyAccountRecordSearch;
use common\component\exception\ErrMap;
use common\component\tool\Tool;
use common\models\OperationLog;


class AccountRecordController extends AuthController
{

    /*资金记录*/
    public function actionRecordList()
    {
        // echo "AccountRecord";
        if(isset($this->get['page'])){
            $currPage = intval($this->get['page']?$this->get['page']:1);
        }else{
            $currPage = 1;
        }
        $pageSize = Tool::getPageSize();

        $Search = (new CompanyAccountRecordSearch())->search($this->get);
        if($Search === false){//验证搜索参数不通过
            $count = 0;
            $recordList = array();
        }else{
            $count = $Search->count();
            $recordList = $Search->with('company')->offset($pageSize*($currPage-1))->limit($pageSize)
                                  ->orderBy(['add_time' => SORT_DESC])
                                  ->asArray()->all();
            if(count($recordList)){
                foreach($recordList as $k => $v){
                    $recordList[$k]['companyname'] = $v['company']['company_name'];
                    unset($recordList[$k]['company']);
                }
            }
        }
        $res = array(
            'list' => $recordList,
            'pageInfo' => array(
                'count' => intval($count),
                'currPage' => $currPage,
                'pageSize' => $pageSize,
            ),
        );
        // P($res);
        return Tool::showRes([0, '获取成功'], $res);
    }

    
    /*统计*/

    
}
